class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k) {
        map<int, int>mp;
        int sum = 0;
        int ans = 0;
        mp[0] = 1;
        for (auto x : nums) {
            sum += x;
            int z = (sum % k + k) % k;
            ans += mp[z];
            mp[z]++;
        }
        return ans;
    }
};